package com.stox.shared.core.beans;

import java.util.Comparator;

public class PropertyDescriptorIndexComparator implements
		Comparator<PropertyDescriptor> {

	private static PropertyDescriptorIndexComparator instance;
	
	public static PropertyDescriptorIndexComparator getInstance(){
		if(null == instance){
			instance = new PropertyDescriptorIndexComparator();
		}
		return instance;
	}
	
	private PropertyDescriptorIndexComparator() {
		
	}
	
	@Override
	public int compare(PropertyDescriptor o1, PropertyDescriptor o2) {
		if(null == o1 && null != o2){
			return -1;
		}else if(null != o1 && null == o2){
			return 1;
		}else if(o1 != null && o2 != null){
			return o1.getIndex() > o2.getIndex() ? 1 : (o1.getIndex() < o2.getIndex() ? -1 : 0); 
		}
		return 0;
	}

}
